package com.yoso.starter.boot.util;

import com.github.stuxuhai.jpinyin.PinyinException;
import com.github.stuxuhai.jpinyin.PinyinFormat;
import com.github.stuxuhai.jpinyin.PinyinHelper;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 *   拼音工具类
 * </p>
 *
 * @author Michael Xu
 * @version 1.0
 * @date 2023/4/3 18:25
 */
@Slf4j
public class PinYinUtils {


    public static String changeToMarkPinYin(String pinYinStr) {
        String tempStr = null;
        try {
            tempStr = PinyinHelper.convertToPinyinString(pinYinStr, "", PinyinFormat.WITH_TONE_MARK);
        } catch (Exception var3) {
            var3.printStackTrace();
        }

        return tempStr;
    }

    public static String changeToNumberPinYin(String pinYinStr) {
        String tempStr = null;

        try {
            tempStr = PinyinHelper.convertToPinyinString(pinYinStr, "", PinyinFormat.WITH_TONE_NUMBER);
        } catch (Exception var3) {
            var3.printStackTrace();
        }

        return tempStr;
    }

    public static String changeToTonePinYin(final String pinYinStr) {
        String tempStr = null;

        try {
            tempStr = PinyinHelper.convertToPinyinString(pinYinStr, "", PinyinFormat.WITHOUT_TONE);
        } catch (PinyinException var3) {
            log.error(var3.getMessage());
        }

        return tempStr;
    }

    public static String changeToGetShortPinYin(String pinYinStr) {
        String tempStr = null;

        try {
            tempStr = PinyinHelper.getShortPinyin(pinYinStr);
        } catch (Exception var3) {
            log.error(var3.getMessage(), var3);
        }

        return tempStr;
    }

    public static boolean checkPinYin(char pinYinStr) {
        boolean check = false;

        try {
            check = PinyinHelper.hasMultiPinyin(pinYinStr);
        } catch (Exception var3) {
            log.error(var3.getMessage(), var3);
        }

        return check;
    }
}
